package com.jason.campusinn.utils;

import android.text.format.DateFormat;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeUtil {


    /***
     * 获取yyyyMMdd格式时间
     * @param date
     * @param formatter
     * @return
     */
    public static String getYYYYMMDD(Date date, DateFormat formatter){
        String yyyymmdd = formatter.format("yyyyMMdd",date).toString();
        return yyyymmdd;
    }

    /***
     * 获取当前月、日、周、时、分
     * @param date
     * @param formatter
     * @return dTimeStr
     */
    public static String getFormattedDateString(Date date, DateFormat formatter){

        String dTimeStr="";
        LogUtil.d("It is " + formatter.format("MM月dd日 EE kk:mm ",date));
        LogUtil.d("It is " + formatter.format("E yyyy.MM.dd 'at' hh:mm:ss a zzz",date));
        dTimeStr=formatter.format("MM月dd日 EE kk:mm",date).toString();
        return dTimeStr;
    }

    /***
     * 获取MM月dd日格式时间
     * @param date
     * @param formatter
     * @return
     */
    public static String getMMDD(Date date, DateFormat formatter){

        String yyddStr=formatter.format("MM月dd日",date).toString();
        return yyddStr;
    }

    /***
     * 获取kk:mm格式时间
     * @param date
     * @param formatter
     * @return
     */
    public static String getkkmm(Date date, DateFormat formatter){

        String kkmmStr = formatter.format("kk:mm",date).toString();
        return kkmmStr;
    }
    /***
     * 根据输入的日期获取当日是周几
     * @param yymmdd
     * @return
     * @throws ParseException
     */
    public static String getWeek(String yymmdd) {
        String weekStr = "";

        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        Date date = null;
        try {
            date = format.parse(yymmdd);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        DateFormat dateFormat = new DateFormat();
        weekStr = dateFormat.
                format("E",date).toString();
        return weekStr;
    }
}
